﻿<Window x:Class="osm2mssql.Importer.Views.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:ViewModel="clr-namespace:osm2mssql.Importer.ViewModel"  Title="osm2mssql" Height="550" MinWidth="500" Width="800" Icon="../Images/App.ico">
    <Window.Resources>
        <ViewModel:ImporterViewModel x:Key="vm"/>
    </Window.Resources>
    <Grid DataContext="{StaticResource vm}">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="500"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <ListBox ItemsSource="{Binding LogRows}" Grid.Column="1" Margin="3"/>
        <TabControl>
            <TabItem>
                <TabItem.Header>
                    <StackPanel Orientation="Horizontal">
                        <Image Height="16" Margin="3,0,3,0" Source="../Images/world.png"/>
                        <TextBlock Text="Importer" VerticalAlignment="Center" Margin="3"/>
                    </StackPanel>
                </TabItem.Header>
                <Grid Margin="4">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="*"/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>

                    <GroupBox Margin="3" Grid.Row="0" Header="{StaticResource DatabaseConnectionSettings}">
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="Auto"/>
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="*"/>
                            </Grid.RowDefinitions>
                            <Image Height="120" Grid.Column="2" Margin="3" Source="../Images/osm2mssql.png" Grid.RowSpan="10"/>

                            <TextBlock Margin="3" VerticalAlignment="Center" HorizontalAlignment="Right" Grid.Column="0" Grid.Row="0" Text="{StaticResource Host}"/>
                            <Grid Grid.Column="1" Grid.Row="0">
                                <TextBox Margin="3" VerticalAlignment="Center" Text="{Binding Model.Host,Mode=TwoWay}"/>
                                <Image Height="16" Opacity="0.8" IsHitTestVisible="False" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="3" Source="../Images/world.png"/>
                            </Grid>

                            <TextBlock Margin="3" VerticalAlignment="Center" HorizontalAlignment="Right" Grid.Column="0" Grid.Row="1" Text="{StaticResource Database}"/>
                            <Grid Grid.Column="1" Grid.Row="1">
                                <TextBox Margin="3" VerticalAlignment="Center" Grid.Column="1" Grid.Row="1" Text="{Binding Model.Database,Mode=TwoWay}"/>
                                <Image Height="16" Opacity="0.8" IsHitTestVisible="False" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="3" Source="../Images/star.png"/>
                            </Grid>

                            <TextBlock Margin="3" VerticalAlignment="Center" HorizontalAlignment="Right" Grid.Column="0" Grid.Row="2" Text="{StaticResource Username}"/>
                            <Grid Grid.Column="1" Grid.Row="2">
                                <TextBox Margin="3" VerticalAlignment="Center" Grid.Column="1" Grid.Row="2" Text="{Binding Model.Username,Mode=TwoWay}"/>
                                <Image Height="16" Opacity="0.8" IsHitTestVisible="False" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="3" Source="../Images/user.png"/>
                            </Grid>

                            <TextBlock Margin="3" VerticalAlignment="Center" HorizontalAlignment="Right" Grid.Column="0" Grid.Row="3" Text="{StaticResource Password}"/>
                            <Grid Grid.Column="1" Grid.Row="3">
                                <TextBox Margin="3" VerticalAlignment="Center" Grid.Column="1" Grid.Row="3" Text="{Binding Model.Password,Mode=TwoWay}"/>
                                <Image Height="16" Opacity="0.8" IsHitTestVisible="False" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="3" Source="../Images/key.png"/>
                            </Grid>

                            <Image Grid.Row="5" Grid.Column="0" Height="16">
                                <Image.Style>
                                    <Style TargetType="Image">
                                        <Setter Property="Source" Value="../Images/ok.png"/>
                                        <Style.Triggers>
                                            <DataTrigger Binding="{Binding LastTryConnectionResult}" Value="Unknown">
                                                <Setter Value="Collapsed" Property="Visibility"/>
                                            </DataTrigger>
                                            <DataTrigger Binding="{Binding LastTryConnectionResult}" Value="Successful">
                                                <Setter Value="../Images/ok.png" Property="Source"/>
                                            </DataTrigger>
                                            <DataTrigger Binding="{Binding LastTryConnectionResult}" Value="Error">
                                                <Setter Value="../Images/error.png" Property="Source"/>
                                            </DataTrigger>
                                            <DataTrigger Binding="{Binding LastTryConnectionResult}" Value="DbAlreadyExists">
                                                <Setter Value="../Images/warning.png" Property="Source"/>
                                            </DataTrigger>
                                        </Style.Triggers>
                                    </Style>
                                </Image.Style>
                            </Image>
                            <Button Margin="3" VerticalAlignment="Center" Command="{Binding TryToConnect}" Grid.Row="5" Grid.Column="1" Content="{StaticResource TryToConnect}"/>
                        </Grid>
                    </GroupBox>

                    <GroupBox Grid.Row="1" Header="{StaticResource Import}" Margin="3">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="*"/>
                                <RowDefinition Height="Auto"/>
                            </Grid.RowDefinitions>
                            <ItemsControl ItemsSource="{Binding Tasks}" Margin="3" Grid.Row="0">
                                <ItemsControl.Template>
                                    <ControlTemplate>
                                        <ScrollViewer HorizontalContentAlignment="Stretch" VerticalScrollBarVisibility="Auto">
                                            <ItemsPresenter HorizontalAlignment="Stretch"/>
                                        </ScrollViewer>
                                    </ControlTemplate>
                                </ItemsControl.Template>
                                <ItemsControl.ItemTemplate>
                                    <DataTemplate>
                                        <CheckBox IsChecked="{Binding IsEnabled, Mode=TwoWay}" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Center">
                                            <Grid Margin="3">
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="Auto"/>
                                                    <ColumnDefinition Width="*"/>
                                                    <ColumnDefinition Width="Auto"/>
                                                    <ColumnDefinition Width="64"/>
                                                    <ColumnDefinition Width="Auto"/>
                                                </Grid.ColumnDefinitions>
                                                <Image Height="16" Margin="3">
                                                    <Image.Style>
                                                        <Style TargetType="Image">
                                                            <Style.Triggers>
                                                                <DataTrigger Binding="{Binding Result}" Value="Pending">
                                                                    <Setter Property="Source" Value="../Images/arrowright.png"/>
                                                                </DataTrigger>
                                                                <DataTrigger Binding="{Binding Result}" Value="InProgress">
                                                                    <Setter Property="Source" Value="../Images/refresh.png"/>
                                                                </DataTrigger>
                                                                <DataTrigger Binding="{Binding Result}" Value="Error">
                                                                    <Setter Property="Source" Value="../Images/error.png"/>
                                                                </DataTrigger>
                                                                <DataTrigger Binding="{Binding Result}" Value="Successful">
                                                                    <Setter Property="Source" Value="../Images/ok.png"/>
                                                                </DataTrigger>
                                                            </Style.Triggers>
                                                        </Style>
                                                    </Image.Style>
                                                </Image>
                                                <TextBlock Grid.Column="1" Text="{Binding Name}" VerticalAlignment="Center"/>
                                                <TextBlock Grid.Column="2" VerticalAlignment="Center" Text="{Binding AdditionalInfos}"/>
                                                <ProgressBar Grid.Column="3" Margin="3" Height="13" IsIndeterminate="True" VerticalAlignment="Center">
                                                    <ProgressBar.Style>
                                                        <Style TargetType="ProgressBar">
                                                            <Setter Property="Visibility" Value="Collapsed"/>
                                                            <Style.Triggers>
                                                                <DataTrigger Binding="{Binding Result}" Value="InProgress">
                                                                    <Setter Property="Visibility" Value="Visible"/>
                                                                </DataTrigger>
                                                            </Style.Triggers>
                                                        </Style>
                                                    </ProgressBar.Style>
                                                </ProgressBar>
                                                <TextBlock Grid.Column="4" Text="{Binding Duration,StringFormat=hh\\:mm\\:ss}" VerticalAlignment="Center">
                                            <TextBlock.Style>
                                                <Style TargetType="TextBlock">
                                                    <Setter Property="Visibility" Value="Visible"/>
                                                    <Style.Triggers>
                                                        <DataTrigger Binding="{Binding Result}" Value="Pending">
                                                            <Setter Property="Visibility" Value="Collapsed"/>
                                                        </DataTrigger>
                                                    </Style.Triggers>
                                                </Style>
                                            </TextBlock.Style>
                                                </TextBlock>
                                            </Grid>
                                        </CheckBox>
                                    </DataTemplate>
                                </ItemsControl.ItemTemplate>
                            </ItemsControl>
                            <Image  Grid.Row="0" Source="../Images/osm.png" Opacity="0.15" Margin="8"/>
                            <Button IsEnabled="{Binding IsNotProcessing}" Command="{Binding StartImport}" Margin="3" VerticalAlignment="Center" Grid.Row="1" Content="{StaticResource StartImport}"/>
                        </Grid>
                    </GroupBox>
                </Grid>
            </TabItem>
        </TabControl>
    </Grid>
</Window>

    